{layout name="/public/layout_index" /}



<div id="app" v-cloak>

  <div class="card">
      <div class="card-body">
        <h3 class="card-title">出入库</h3>
        <h6 class="card-subtitle">请通过产品编码进行出入库操作</h6>
        <hr class="m-t-0 m-b-0">
      </div>
      <div class="card-body clearfix">


        <el-form :model="form" @submit.prevent="return false" label-width="80px">
          <!-- <el-form-item label="编码">
            <el-input
              ref="input"
              v-model="form.code"
              @keyup.enter.native="parseCode"
              placeholder="输入编码">
            </el-input>
          </el-form-item> -->
          <el-form-item label="编码">
            <el-select v-model="form.code" filterable placeholder="请选择">
              <el-option
                v-for="item in AllGoods"
                @keyup.enter.native="parseCode"
                ref="input"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="出入库">
            <el-radio-group v-model="form.type" size="medium">
              <el-radio-button label="in">入库</el-radio-button>
              <el-radio-button label="out">出库</el-radio-button>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="库位">
            <el-select v-model="form.store" filterable placeholder="请选择">
              <el-option
                v-for="item in storeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>

          </el-form-item>

          <el-form-item label="数量">
            <el-input-number
              v-model="form.num"
              >
            </el-input-number>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="parseCode">提交</el-button>
          </el-form-item>
        </el-form>



      </div>
  </div>



</div>



<script>

var main=new Vue({
  el:"#app",
  data:{
    form:{
      store:"",
      type:"in",
      code:"",
      num:1
    },
    AllGoods:[],
    storeList:[]

  },
  methods: {
    init(){
      var that=this;
      APP.ajax("getAllStore",{},function(msg){
        if (msg.result){
          that.storeList=msg.data;
        }else{
          APP.alert(msg.data);
        }
      });
      APP.ajax("getAllGoods",{},function(msg){
        if (msg.result){
          that.AllGoods=msg.data;
        }else{
          APP.alert(msg.data);
        }
      });

    },

    parseCode(){
      var code=this.form.code;

      if (code){
        if (code.startsWith("-i")){
          this.setIn(code.substr(2));
        }else if (code.startsWith("-o")){
          this.setOut(code.substr(2));
        }else{
          this.setCode(code);
        }
      }else{
        APP.alert("请输入编码");
      }
    },
    setIn(code){
      this.form.type="in";
      this.form.store=code;
      this.form.code="";
      this.form.num=1;
    },
    setOut(code){
      this.form.type="out";
      this.form.store=code;
      this.form.code="";
      this.form.num=1;
    },
    setCode(code){
      var that=this;
      APP.ajax("save",{data:this.form},function(msg){
        if (msg.result){
          APP.alert(msg.data,true);
        }else{
          APP.alert(msg.data);
        }
        that.form.code="";
        that.$refs.input.focus();
      });
    }

  },
  mounted(){
    var that=this;
    this.$nextTick(function () {
      that.init();
    })
  }

});

</script>
